<!DOCTYPE table PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
  <head>
    <title>
      Prodiags Schedule
    </title>
    <link href="css/assetReg.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
   <script type="text/javascript" language="JavaScript">
   function search(url){
	   		var form = document.scheduleSearchForm;
	   		form.action="<%=request.getContextPath()%>/"+url;
	   		form.submit();
    }
   function searchModalType(url){
	   var form = document.modelScheduleForm;
  		form.action="<%=request.getContextPath()%>/"+url;
  		form.submit();
	   
	   
   }
   function processProDiagsSchedule(ele){
	   var id = $(ele).attr("id");
	   var form = ele.form;
     if($(ele).val()=='Edit'){
       $('[name=viewComponents'+id+']').hide();
       $('[name=editComponents'+id+']').show();
       $('[name=Edit'+id+']').val('Update');
     }else{
    	 $('[name=editComponents'+id+']').each(function(index){
             $(this).hide();
             $('[name=viewComponents'+id+']').eq(index).text($("select",this).val()).show();
            	 
    	 });
       $('[name=Edit'+id+']').val('Edit');
       form.action="<%=request.getContextPath()%>/updateSchedule.htm";
       form.submit();
     }
    
   }
   
   function processProDiagsScheduleConf(ele){
	     var id = $(ele).attr("id");
	     if($(ele).val()=='Edit'){
	       $('[name=viewComponentsConf'+id+']').hide();
	       $('[name=editComponentsConf'+id+']').show();
	       $('[name=Confedit'+id+']').val('Update');
	     }else{
	       $('[name=editComponentsConf'+id+']').each(function(index){
	         $(this).hide();
	         $('[name=viewComponentsConf'+id+']').eq(index).text($("select",this).val()).show();
	         
	       });
	       $('[name=Confedit'+id+']').val('Edit');
	      // document.getElementById("form"+id).action="<%=request.getContextPath()%>/updateSchedule.htm";
	      // document.getElementById("form"+id).submit();
	     }
	    
	   }
	   function processAllProDiagsSchedule(ele){
	   if($(ele).val()=='Edit All'){
	          $(ele).val('Update All');
	     }else{
			$(ele).val('Edit All');
		 }
	   $('input[name^=Edit]').each(
		function(){
			processProDiagsSchedule(this);
		});
	   }
	   
	   function doAjaxRequest(reqestType){

			var modality=$("#modality option:selected").text();
			var productLine=$("#productLine option:selected").text();
			var url="";
			var data="";
			
			if(reqestType == 'ProductLine'){
				url="getProductLines.htm";
				data="modality="+modality;
			}

			else if(reqestType == 'ModelType'){
				url="getModelTypes.htm";
				data="modality="+modality+"&productLine="+productLine;
			}
			
			

		    $.ajax({
		    type: "POST",
		    dataType :"text",
		    url:url ,
		    data:data ,
		    success: function(response,e){
		    	var array = response.split(',');
		    	if(reqestType == 'ProductLine'){
			    	$('#productLine').empty();
			    	$(array).each(function(item) {
			    		$('#productLine').append("<option value="+array[item]+">"+array[item]+"</option>");
					});
			    	}
		    	else if(reqestType == 'ModelType'){
		    		$('#models').empty();
			    	$(array).each(function(item) {
			    		$('#models').append("<option value="+array[item]+">"+array[item]+"</option>");
					});
				}

		    },

		    });
	   }
   </script>
  </head>
  <body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
  <h1 align="center">ProDiags Schedule</h1>
  <div align="center" > 
<form:form commandName="scheduleBean" id="scheduleSearchForm" name="scheduleSearchForm" method="post">
<b>  System Id </b> 
 

<form:input path="systemId"></form:input>
<input type="submit" value="Search" onclick="javascript:search('filterSchedules.htm');"/>
<br/>
</form:form>
<c:if test="${not empty schedules && scheduleBean.systemId ne null}">
<table bgcolor="#000000"  border="0">
<tr bgcolor="#6875A3"><td class="stdSmallerHeader_white" colspan="8" align="center">SYSTEM ID: LXBAY14ANET</td></tr>
      <tr align="center" bgcolor="#FFFFFF">
          <th>
            System Id/Model Type
          </th>      
          <th>
            Task Name
          </th>
          <th>
            Iterations
          </th>
      
          <th>
            Day
          </th>
          <th>
            Hour
          </th>
          <th>
            Minutes
          </th>
          <th>
            Week
          </th>
          <th>
            Edit
          </th>
      </tr> 
      <c:forEach items="${schedules}" var="schedule">
      <form:form id="form${schedule.systemId }" >
          <input type="hidden" name="systemId" value="${schedule.systemId }">
      <input type="hidden" name="modelType" value="${schedule.modelType }">
      <input type="hidden" name="taskName" value="${schedule.taskName }">
      <input type="hidden" name="iterations" value="${schedule.iterations}"/>
      
        <tr align="center" bgcolor="#FFFFFF">
          <td>
            ${schedule.systemId }/ ${schedule.modelType }
          </td>
          <td>
            ${schedule.taskName }
          </td>
          <td>
            ${schedule.iterations}
            </td>
          <td>
          	  
              <div name="viewComponents${schedule.systemId }">
                 ${schedule.day }
              </div>
              <div name="editComponents${schedule.systemId }" style="display:  none;">
                <select name="day">
          	  	<c:forEach items="${dayList}" var="day">
          	  		<option value="${day}" <c:if test="${schedule.day == day}">selected=selected</c:if>>${day}</option>
          	  	</c:forEach>
          	  </select>
              </div>
          
          </td>
        <td>
              <div name="viewComponents${schedule.systemId }">
           		${schedule.hour }
            </div>
             <div name="editComponents${schedule.systemId }" style="display:  none;">
               <select name="hour">
          	  	<c:forEach items="${hourList}" var="hour">
          	  		<option value="${hour}" <c:if test="${schedule.hour == hour}">selected=selected</c:if>>${hour}</option>
          	  	</c:forEach>
          	  </select>
            </div>
          </td>
          <td>
           <div name="viewComponents${schedule.systemId }">
            ${schedule.minute }
            </div>
             <div name="editComponents${schedule.systemId }" style="display:  none;">
             <select name="minute">
          	  	<c:forEach items="${minuteList}" var="minute">
          	  		<option value="${minute}" <c:if test="${schedule.minute == minute}">selected=selected</c:if>>${minute}</option>
          	  	</c:forEach>
          	  </select>
            </div>
          </td>
          <td>
           <div name="viewComponents${schedule.systemId }">
            ${schedule.week }
            </div>
             <div name="editComponents${schedule.systemId }" style="display:  none;">
               <select name="week">
          	  	<c:forEach items="${weekList}" var="week">
          	  		<option value="${week}" <c:if test="${schedule.week == week}">selected=selected</c:if>>${week}</option>
          	  	</c:forEach>
          	  </select>
            </div>
          </td>
          <td>
        	 <input type="button" name="Edit${schedule.systemId }" value="Edit" id="${schedule.systemId }" onclick="processProDiagsSchedule(this)"/> 
        </td>
        </tr>
        </form:form>
         </c:forEach>
         <c:set var="showButtons" value="true"></c:set>
		  <c:if test="${showButtons}">
		 <tr bgcolor="#6875A3"> <td colspan="8" align="center">
		    <input type="button" value="Edit All" id="editUpdate" onclick="processAllProDiagsSchedule(this)"/> 
		    <input type="button" value="Compare Schedule" id="Compare" onclick="javascript:search('compareSchedules.htm');"/>  
		    <input type="button" value="View Report" id="Report" onclick="javascript:search('scheduleReport.htm');"/>  
		    <input type="button" value="Apply Schedule" id="Apply" onclick="javascript:search('applySchedule.htm');"/>
		    </td>
		    </tr>
		  </c:if>
      </table>
</c:if>
  <br/>
  </div>
    <div style="clear:both;"></div>


<h3 align="center">ProDiags Schedule Configuration for Model Type Level</h3>
<form:form commandName="scheduleBean"  action="?" id="modelScheduleForm" name="scheduleForm1" method="post">
<table border="0" cellpadding="1" cellspacing="1" width="100%"><tbody>
<tr>
<td>
Enter Model Type: 
<form:input path="modelType"></form:input>
</td>
<td> OR Select Modality: 
<select onchange="doAjaxRequest('ProductLine');" id="modality">
<c:forEach var="modality" items="${modalities}">
 <option value="${modality}">${modality}</option>
</c:forEach>
 
</select>
</td>
<td> Product Line 
<select id="productLine" onchange="doAjaxRequest('ModelType');">
</select>
</td>
<td> Model Type: 
<select id="models" name="dropDownModelType">
</select>
</td>
<td><input type="submit" value="Submit"  onclick="javascript:searchModalType('filterSchedules.htm');"/></td>
</tr>
</tbody></table>
 </form:form>
 <c:if test="${not empty schedules && (scheduleBean.modelType ne null||scheduleBean.dropDownModelType ne null)}">
<form action="apply_schedule.htm" id="modelTypeSearchForm">
<table bgcolor="#000000" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td>
<table border="0" cellpadding="1" cellspacing="1" width="100%"><tbody>
<tr bgcolor="#FFFFFF"></tr><tr bgcolor="#6875A3">
<td class="stdSmallerHeader_white" colspan="5" align="center">MODEL TYPE: _LS-ULT-LNX</td></tr>
<tr bgcolor="#FFFFFF">
<th class="stdDarkBlueBold" align="left">&nbsp; Task Name</th>
<th class="stdDarkBlueBold" align="left">&nbsp; Iterations</th>
<th class="stdDarkBlueBold" align="left">&nbsp; Day</th>
<th class="stdDarkBlueBold" align="left">&nbsp; Start Time</th>
<th class="stdDarkBlueBold" align="left">&nbsp; End Time</th></tr>
<c:forEach items="${schedules}" var="schedule">
<tr bgcolor="#FFFFFF">
<td class="stdBold" align="left">&nbsp; ${schedule.taskName }</td>
<td class="stdBold" align="left">

           &nbsp; 1
  
</td>
<td class="stdBold" align="left">
<div name="viewComponentsConf6">
           &nbsp; Daily
   </div>
   <div name="editComponentsConf6" style="display:  none;">
       <select name="day">
    	  	<option value="Daily" >&nbsp; Daily</option>
			<option value="Monday" >&nbsp; Monday</option>
			<option value="Tuesday" >&nbsp; Tuesday</option>
			<option value="Wednesday" >&nbsp; Wednesday</option>
			<option value="Thursday" >&nbsp; Thursday</option>
			<option value="Friday" >&nbsp; Friday</option>
			<option value="Saturday" >&nbsp; Saturday</option>
			<option value="Sunday" >&nbsp; Sunday</option>
    	 </select>
    </div>
</td>
<td class="stdBold" align="left">
<div name="viewComponentsConf6">
           &nbsp; 1
   </div>
   <div name="editComponentsConf6" style="display:  none;">
       <select name="day">
    	  	<option value="1" >&nbsp; 1</option> 
			<option value="2" >&nbsp; 2</option>
			<option value="3" >&nbsp; 3</option>
			<option value="4" >&nbsp; 4</option>
			<option value="5" >&nbsp; 5</option>
			<option value="1" >&nbsp; 6</option> 
			<option value="2" >&nbsp; 7</option>
			<option value="3" >&nbsp; 8</option>
			<option value="4" >&nbsp; 9</option>
			<option value="5" >&nbsp; 10</option>
			<option value="1" >&nbsp; 11</option> 
			<option value="2" >&nbsp; 12</option>
    	 </select>
		<select name="day">
    	  	<option value="1" >&nbsp; AM</option> 
			<option value="2" >&nbsp; PM</option>
		</select>
    </div>
</td><td class="stdBold" align="left">
<div name="viewComponentsConf6">
           &nbsp; 10
   </div>
   <div name="editComponentsConf6" style="display:  none;">
       <select name="day">
    	  	<option value="1" >&nbsp; 1</option> 
			<option value="2" >&nbsp; 2</option>
			<option value="3" >&nbsp; 3</option>
			<option value="4" >&nbsp; 4</option>
			<option value="5" >&nbsp; 5</option>
			<option value="1" >&nbsp; 6</option> 
			<option value="2" >&nbsp; 7</option>
			<option value="3" >&nbsp; 8</option>
			<option value="4" >&nbsp; 9</option>
			<option value="5" >&nbsp; 10</option>
			<option value="1" >&nbsp; 11</option> 
			<option value="2" >&nbsp; 12</option>
    	</select>
		<select name="day">
    	  	<option value="1" >&nbsp; AM</option> 
			<option value="2" >&nbsp; PM</option>
		</select>
    </div>
	</td>
	</tr>
	</c:forEach>
</tbody>
</table>

<tr bgcolor="#FFFFFF"></tr><tr bgcolor="#6875A3"><td class="stdSmallerHeader_white" colspan="3" align="center"><input type="button" value="Edit"  name="Confedit6" id="6" onclick="processProDiagsScheduleConf(this)" /><input type="submit" value="Apply Schedule"/></td></tr>
</tbody></table>
</form> 
 </c:if>

 
</body>
    
</html>